import 'package:flutter/material.dart';

/* 在给定的持续时间内逐渐更改自身填充（padding）属性的 widget */
class PaddingStatic extends StatefulWidget {
  const PaddingStatic({super.key});

  @override
  State<PaddingStatic> createState() => _PaddingStaticState();
}

class _PaddingStaticState extends State<PaddingStatic> {
  double _paddingValue = 10.0;

  @override
  Widget build(BuildContext context) {
    return Container(
      width: double.infinity,
      height: 300,
      decoration: BoxDecoration(
        border: Border.all(color: Colors.black, width: 1),
        borderRadius: BorderRadius.circular(8)
      ),
      child: Column(
        children: [
          ElevatedButton(
            onPressed: () {
              setState(() {
                _paddingValue = _paddingValue == 10.0 ? 50.0 : 10.0;
              });
            },
            child: const Text('切换padding')
          ),

          AnimatedPadding(
            padding: EdgeInsets.all(_paddingValue),
            duration: const Duration(seconds: 1),
            curve: Curves.easeInOut,
            child: Container(
              color: Colors.amber[100],
              width: 100,
              height: 100,
            ),
          )
        ],
      ),
    );
  }
}